package net.comic.services

import net.comic.entities.*
import net.comic.controllers.*

class RateService {
    boolean transactional = true

    def rateComic(comicId, rateValue, userLogged) {
    	def comic = Comic.get(comicId)
    	
    	//	Get previus rates from this user
    	def rateFromUser = Rate.createCriteria().list { ratedBy : userLogged }	//TODO: mirar si es conveniente pillar solo un valor... posible error transcient....

    	//	Remove previus rates	
		rateFromUser?.each() { comic.removeFromRatings( it ) }

    	//	Set rate from user
    	comic.addToRatings(new Rate(rate: rateValue, ratedBy:userLogged))
    }
    
    def ratePage() {
    	
    }
}

